interface parmType {
	url: string
	name: string
	icon: string
	sapp_id: string
	sapp_type: string | number
	app_launcher: string
	processcenter_name: string
}
type fromOrigin = 'appCenter' | 'recentlyAndStar'
//参数转换
const codeMap = {
	appCenter: {
		url: 'form_url',
		name: 'name',
		icon: 'icon',
		sapp_id: 'fb_key',
		sapp_type: 'sapp_type',
		app_launcher: 'app_launcher',
		processcenter_name: 'processcenter_name',
	},
	recentlyAndStar: {
		url: 'link',
		name: 'name',
		icon: 'icon',
		sapp_id: 'id',
		sapp_type: 'sapp_type',
		app_launcher: 'app_launcher',
		processcenter_name: 'processcenter_name',
	},
}
//参数格式化
const formatParm = (data: any, fromOrigin: fromOrigin) => {
	const obj = codeMap[fromOrigin]
	const newData: parmType = {
		url: data[obj.url],
		name: data[obj.name],
		icon: data[obj.icon],
		sapp_id: data[obj.sapp_id],
		sapp_type: data[obj.sapp_type],
		app_launcher: data[obj.app_launcher],
		processcenter_name: data[obj.processcenter_name],
	}
	return newData
}
// 是否是多标签页内嵌的门户
export const isInnerIframePage = () => {
	if (location.href.indexOf('turnOnTheStarter') > 0) {
		return true
	} else {
		return false
	}
}
// 多标签页内嵌的门户跳转方法
export const iframePostMessage = (
	data: any,
	fromOrigin: fromOrigin,
	targetWindow?: any
) => {
	const newParm: parmType = formatParm(data, fromOrigin)
	let w = window.parent || window
	if (targetWindow) {
		targetWindow.baitedaConfig = {
			type: 'turnOnTheStarter',
			...newParm,
		}
		w = targetWindow
	}
	w.postMessage(
		{
			type: 'turnOnTheStarter',
			...newParm,
		},
		'*'
	)
}
